<form class="layui-form layui-form-pane form-search" action="{:sysuri()}" onsubmit="return false" method="get" autocomplete="off">
    <div class="layui-form-item layui-inline">
        <label class="layui-input-inline">
            <input name="keywords" value="{$get.keywords|default=''}" placeholder="{:lang('请输入商品名称/关键字')}" class="layui-input">
        </label>
    </div>

    <div class="layui-form-item layui-inline">
        <label class="layui-input-inline">
            <select name="merchid">
                <option value='0'>供货商</option>
                {foreach $merchList as $meritem}{eq name='meritem.id' value='$vo.merchid|default=0'}
                <option selected disabled value='{$meritem.id}'>{$meritem.merchname}</option>
                {else}
                <option value='{$meritem.id}'>{$meritem.merchname}</option>
                {/eq}
                {/foreach}
            </select>
        </label>
    </div>

    <div class="layui-form-item layui-inline">
        <label class="layui-input-inline">
            <select name="opttype">
                <option value='0'>无标签</option>
                {foreach $tagList as $k=>$v}{eq name='k' value='$opttype'}
                <option selected disabled value='{$k}'>{$v}</option>
                {else}
                <option value='{$k}'>{$v}</option>
                {/eq}
                {/foreach}
            </select>
        </label>
    </div>

    <div class="layui-form-item layui-inline">
        <input type="hidden" name="type" value="{$type|default='index'}">
        <button class="layui-btn layui-btn-primary"><i class="layui-icon">&#xe615;</i> {:lang('搜 索')}</button>


{if isset($type) and $type eq 1}
        <button type="button" data-form-export="{:url('index')}?type={$type|default=1}" class="layui-btn layui-btn-primary">
            <i class="layui-icon layui-icon-export"></i> 导 出
        </button>
        {else}
        {/if}

    </div>
</form>

<script>
    const currentTime = new Date();
    const year = currentTime.getFullYear();
    const month = currentTime.getMonth() + 1; // 月份从0开始，因此需要加1
    const day = currentTime.getDate();
    const hours = currentTime.getHours();
    const minutes = currentTime.getMinutes();
    const seconds = currentTime.getSeconds();



    require(['excel'], function (excel) {
        excel.bind(function (data) {

            // 设置表格内容
            data.forEach(function (item, index) {
				
                data[index] = [item.title, item.subtitle,item.marketprice,item.costprice,item.costnum,item.total,item.tag_str];
            });

            // 设置表头内容
            data.unshift(['商品名称', '副标题','售价','成本单价','数量','库存','标签']);

            // 可选，自动计算列序号
            var lastCol = layui.excel.numToTitle((function (count, idx) {
                for (idx in data[0]) count++;
                return count;
            })(0));

            // 可选，设置表头样式
            layui.excel.setExportCellStyle(data, 'A1:' + lastCol + '1', {
                s: {
                    font: {sz: 14, bold: true, color: {rgb: "FFFFFF"}, shadow: true},
                    fill: {bgColor: {indexed: 64}, fgColor: {rgb: "5FB878"}},
                    alignment: {vertical: 'center', horizontal: 'center'}
                }
            });

            // 可选，设置内容样式
            var style1 = {
                fill: {bgColor: {indexed: 64}, fgColor: {rgb: "EAEAEA"}},
                alignment: {vertical: 'center', horizontal: 'center'}
            }, style2 = {
                fill: {bgColor: {indexed: 64}, fgColor: {rgb: "FFFFFF"}},
                alignment: {vertical: 'center', horizontal: 'center'}
            };
            layui.excel.setExportCellStyle(data, 'A2:' + lastCol + data.length, {
                s: style1
            }, function (rawCell, newCell, row, config, currentRow, currentCol, fieldKey) {
                /* 判断并转换单元格数据为对象，以便初始化样式 */
                typeof rawCell !== 'object' && (rawCell = {v: rawCell});
                rawCell.s = Object.assign({}, style2, rawCell.s || {});
                return (currentRow % 2 === 0) ? newCell : rawCell;
            });

            // 可选，设置表格行宽高，需要设置最后的行或列宽高，否则部分不生效 ？？？
            var rowsC = {1: 40}, colsC = {A: 100, B: 100};
            rowsC[data.length] = 20, colsC[lastCol] = 160;
            this.options.extend = {
                '!rows': layui.excel.makeRowConfig(rowsC, 20), // 设置每行高度，默认 20
                '!cols': layui.excel.makeColConfig(colsC, 160) // 设置每行宽度，默认 160
            };

            // 其他更多样式，可以配置 this.options.extend 参数，每次执行 bind 会被重置
            // 在线文档：http://excel.wj2015.com/_book/docs/%E5%87%BD%E6%95%B0%E5%88%97%E8%A1%A8/%E6%A0%B7%E5%BC%8F%E8%AE%BE%E7%BD%AE%E7%9B%B8%E5%85%B3%E5%87%BD%E6%95%B0.html

            return data;
        }, '商品列表-'+year+month+day+hours+minutes+seconds);
    });
</script>